from multiprocessing import Pool
import multiprocessing
import os

def worker(name):
    return "hello_%s_pid:%s_ppid:%s" % (name,os.getpid(),os.getppid())


if __name__ == "__main__":
    # 产生一个进程池
    pool = Pool(processes=4)  # processes最好和cpu核数相等
    result = []
    for i in range(1000):
        name = "worker_%d" % i
        pc = pool.apply_async(worker,args=(name,))
        result.append(pc)

    print("1111111111")
    pool.close()
    print("2222222")
    pool.join()
    print("33333")

    for x in result:
        print(x.get())